<?php
/**
 * Buffet Framework: Default Template Functions
 * 
 * This file contains the template functions that add functionality to the 
 * default features of the theme.
 *
 * As of 0.6, the framework will read template.php from the respective child
 * theme folder.
 * 
 * @package Buffet
 * @subpackage API
 */

// Include theme hooks and filters here
add_action('init', 'buffet_launcher');

add_action('wp_head', 'buffet_head', 50);
add_action('bf_jquery', 'buffet_jquery');

add_action('bf_header', 'buffet_header');
add_action('bf_above_content', 'bf_breadcrumbs');

add_action('bf_home_tpl', 'buffet_home');

add_action('bf_below_post', 'buffet_author_information');

add_action('bf_below_container', 'get_sidebar');

add_action('bf_footer', 'buffet_footer');

function buffet_launcher() {
	/* Import Blueprint CSS styles */
	bf_add_stylesheet(get_template_directory_uri() . '/css/blueprint/reset.css');
	bf_add_stylesheet(get_template_directory_uri() . '/css/blueprint/typography.css');
	bf_add_stylesheet(get_template_directory_uri() . '/css/blueprint/forms.css');

	/* Import custom layouts (located at /css/layouts/) */
	bf_add_stylesheet(get_template_directory_uri() . '/css/layouts/2c-r-fixed.css');

	/* Import default stylesheet */
	bf_add_stylesheet(get_template_directory_uri() . '/style.css');

    if (!is_admin()) {
		wp_enqueue_script( 'jbreadcrumb', get_template_directory_uri() . '/includes/js/jquery.jbreadcrumb.min.js', array('jquery-ui-core') );
		wp_enqueue_script( 'superfish', get_template_directory_uri() . '/includes/js/superfish/superfish.js', 'jquery' );
		wp_enqueue_script( 'jquery-scrollto', get_template_directory_uri() . '/includes/js/jquery.scrollto.min.js', 'jquery' );
		wp_enqueue_script( 'buffet-base', get_template_directory_uri() . '/includes/js/base.js', 'jquery' );
	}
}

function buffet_head() {
	// WordPress only knows whether the page type at wp_head hook
	if ( is_front_page() || is_home() || is_archive() || is_search() ) {
		add_action('bf_below_content', 'buffet_pagenav');
	}	
?>
	<meta name="description" content="<?php bloginfo('description') ?>" />

	<?php if ( !class_exists('All_in_One_SEO_Pack') && (is_search() || is_author()) ) : ?>
	<meta name="robots" content="noindex, nofollow" />
	<?php endif ?>

	<?php bf_load_stylesheets() ?>

	<link rel="alternate" type="application/rss+xml" href="<?php bf_rss_url() ?>" title="<?php printf( __( '%s latest posts', 'arras' ), wp_specialchars( get_bloginfo('name'), 1 ) ) ?>" />
	<link rel="alternate" type="application/rss+xml" href="<?php bf_comments_rss_url() ?>" title="<?php printf( __( '%s latest comments', 'arras' ), wp_specialchars( get_bloginfo('name'), 1 ) ) ?>" />

	<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
	<!--[if lt IE 7]><script src="<?php echo get_template_directory_uri() ?>/includes/js/ie7-js/IE8.js" type="text/javascript"></script><![endif]-->
<?php
}

function buffet_header() {
?>
	<div id="header" <?php bf_header_class() ?>>
	<div id="branding" class="clearfix">
        <div class="logo">
			<?php if ( is_home() || is_front_page() ) : ?>
	            <h1 class="blog-name"><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1>
				<h2 class="blog-description"><?php bloginfo('description'); ?></h2>
			<?php else: ?>
	            <span class="blog-name"><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></span>
				<span class="blog-description"><?php bloginfo('description'); ?></span>
			<?php endif; ?>
        </div><!-- .logo -->
		<div id="searchbar">
			<?php include (TEMPLATEPATH . '/searchform.php'); ?>
		</div><!-- #searchbar -->
	</div><!-- #branding -->
    </div><!-- #header -->
<?php
	buffet_navigation();
}

function buffet_navigation() {
?>
	<div class="menu clearfix">
		<ul id="nav" class="nav clearfix">
			<li><a href="<?php bloginfo('url') ?>" title="<?php bloginfo('name') ?>"><?php echo bf_get_option('home_link') ?></a></li>
			<?php if ( !bf_get_option('topnav_linkcat') ) : ?>
			<?php wp_list_categories('hierarchical=false&orderby=id&hide_empty=1&title_li=&exclude=1'); ?>
			<?php else : ?>
			<?php wp_list_bookmarks('category='.bf_get_option('topnav_linkcat').'&show_private=1&hide_invisible=0&title_li=&categorize=0&orderby=id&echo=') ?>
			<?php endif ?>
		</ul>
		<ul class="rss-links clearfix">
			<li><a href="<?php bloginfo('rss2_url') ?>" rel="alternate" type="application/rss+xml" title="<?php printf( __( '%s Posts RSS Feed', 'arras' ), wp_specialchars( get_bloginfo('name'), 1 ) ) ?>">
				<?php _e('Posts', 'buffet') ?>
			</a></li>
			<li><a href="<?php bloginfo('comments_rss2_url') ?>" rel="alternate" type="application/rss+xml" title="<?php printf( __( '%s Comments RSS Feed', 'arras' ), wp_specialchars( get_bloginfo('name'), 1 ) ) ?>">
					<?php _e('Comments', 'buffet') ?>
			</a></li>
		</ul>
	</div>
<?php
}

function buffet_home() {
	global $paged;

	get_posts('cat=' . bf_get_option('news_cat') . '&paged=' . $paged);
	if (have_posts()) : while (have_posts()) : the_post();
	bf_newsheader();
	bf_newsbody();
	bf_newsfooter();
	endwhile; endif;
}

function buffet_pagenav() {
?>
	<?php if ( function_exists('wp_pagenavi') ) : wp_pagenavi(); else : ?>
	<div class="navigation">
		<div class="floatLeft"><?php next_posts_link( __('&laquo; Older Entries', 'buffet') ) ?></div>
		<div class="floatRight"><?php previous_posts_link( __('Newer Entries &raquo;', 'buffet') ) ?></div>
	</div>
	<?php endif;
}

function buffet_author_information() {
	echo '<div class="author-desc vcard">';
	echo '<h5>Author Information</h5>';
	echo '<div class="fn description">';
	the_author_description();
	echo '</div></div>';
}

function buffet_footer() {
?>
	<div id="footer">
		<div class="footer-message">
			<?php echo stripslashes(bf_get_option('footer_message')); ?>
		</div>
    </div><!-- #footer -->
<?php	
}

/* End of file template.php */
/* Location: ./includes/template.php */
